home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / WINDOWS / MSWLOG12.ARJ / HANOI.LG < prev    next >
Text File  |  1992-07-22  |  1KB  |  54 lines

  1. to hanoi :number 
  2. !
  3. ! Towers of Hanoi
  4. ! Meyer A. Billmers
  5. ! November, 1983
  6. !
  7. ! This procedure plays a graphic version of the Towers of Hanoi puzzle
  8. ! The argument is the number of disks in the configuration.
  9. !
  10. ! c.f. putdisk, towercnt,towerset, hanoihlpr
  11. local "from
  12. local "to
  13. local "other
  14. local "datfil
  15. make "datfil openw "hanoi.dat
  16. fileprint :datfil (sentence [Hanoi of ] :number [towers Started at: ] time)
  17. ! to change the starting and ending needles, change the next three assignments
  18. make "from 1
  19. make "to 3
  20. make "other 2
  21. cs
  22. ht
  23. ! first we draw the table and the golden needles
  24. pencolor 255 0 0
  25. pu
  26. setxy "-350 "-100
  27. pd
  28. setxy 350 "-100
  29. pu
  30. setx -240
  31. pd
  32. fd 250
  33. pu
  34. setxy "-15 "-100
  35. pd
  36. fd 250
  37. pu
  38. setxy 210 "-100
  39. pd
  40. fd 250
  41. make "tower1 0
  42. make "tower2 0
  43. make "tower3 0
  44. ! draw the initial stack of disks. note that putdisk draws the 
  45. ! "fixed up" towers.
  46. repeat :number [putdisk :from :number - repcount + 1 "final; \
  47.   if :from = 1 [make "tower1 :tower1 + 1] \
  48.     [if :from = 2 [make "tower2 :tower2 + 1] [make "tower3 :tower3 + 1]]]
  49. hanoihlpr :number :from :to :other
  50. fileprint :datfil (sentence [Hanoi Ended at: ] time)
  51. close :datfil
  52. end
  53.